/* Copyright (C) 2008  Romolo Camplani, Marco Fortunato, Marco Marelli, Guido Rota, Fabio A. Schreiber et al.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.dei.perla.parser.clauses;

import org.dei.perla.parser.util.GenericCollection;

/**
 * Una collezione di <tt>SamplingIfEvery</tt>. Definisce un insieme di condizioni e relativi rate di campionamento. 
 */
public class SamplingIfEveryList extends GenericCollection<SamplingIfEvery> {

	/**
	 * Restituisce lo spezzone di codice "perla" corrispondente
	 */
	public String toString()
	{
		String stringToReturn = "";
		
		if (this.size() == 1) {
			
			stringToReturn = this.get(0).toString();
			stringToReturn = stringToReturn.replace("TRUE ", "");
			
		} else if (this.size() > 1) {
			
			// Scorre tutti gli IfEvery nella lista..
			for(int i = 0; i < this.size(); i++) {
				
				if (i != this.size() - 1) {
				
					stringToReturn += "IF ";
					
				} else {
					
					stringToReturn += "ELSE ";
				}

				// Aggiunge l'IfEvery corrente
				stringToReturn += this.get(i) + "\n";
			}
			
			// Tolgo un \n di troppo
			stringToReturn = stringToReturn.substring(0, stringToReturn.length() - "\n".length());
			
			
		} else {
			
			// .. aggiunge un messaggio di errore
			stringToReturn += "<if_every_list>";
		}	
		
		// Ritorna la string costruita
		return stringToReturn;
	}
}
